package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.NewsDAO;
import com.zerosky.crm.po.News;
import com.zerosky.crm.service.NewsService;
import com.zerosky.crm.util.PageInfo;

@Service(value="newsService")
public class NewsServiceImpl implements NewsService {
	@Autowired
	private NewsDAO newsDAO; // News数据接口

	@Override
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public int deleteNews(Integer id) {
		return newsDAO.deleteNews(id);

	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<News> getPageInfoNewsList(Map map) {
		PageInfo<News> page = new PageInfo<News>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));

		// 写入数据
		map.put("pageNo", begin);
		List<News> list = newsDAO.getNewsList(map);
		page.setList(list);

		int count = newsDAO.countNews(map);// 获取总记录
		page.setPageCount(count);

		return page;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public News getNewsById(Integer id) {
		return newsDAO.getNewsById(id);

	}

	@Override
	public int saveNews(News news) {
		return newsDAO.saveNews(news);
	}

	@Override
	public int updateNews(News news) {
		return newsDAO.updateNews(news);
	}

}
